home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / Apple Game Sprockets / Examples / InputSprocketPPTest / ISpTestMain.cp < prev    next >
Encoding:
Text File  |  1996-05-16  |  7.5 KB  |  347 lines  |  [TEXT/CWIE]

  1. /*
  2.  *
  3.  *
  4.  */
  5.  
  6.  
  7. // ===========================================================================
  8. //    <PP Starter Source>.cp         ©1994-1995 Metrowerks Inc. All rights reserved.
  9. // ===========================================================================
  10. //
  11. //    This file contains the starter code for a PowerPlant application
  12.  
  13. #include "ISpTestMain.h"
  14. #include <Types.h>
  15. #include "InputSprocket.h"
  16.  
  17. #include <LGrowZone.h>
  18. #include <LWindow.h>
  19. #include <PP_Messages.h>
  20. #include <PP_Resources.h>
  21. #include <PPobClasses.h>
  22. #include <UDrawingState.h>
  23. #include <UMemoryMgr.h>
  24. #include <URegistrar.h>
  25. #include <LEditField.h>
  26. #include <Events.h>
  27.  
  28. #include "ISpTestGlobals.h"
  29. #include "ISpEventPane.h"
  30. #include "ISpElementView.h"
  31. #include "ISpLQuitWindow.h"
  32.  
  33. // put declarations for resource ids (ResIDTs) here
  34.  
  35. const ResIDT    window_Sample        = 1;    // EXAMPLE
  36.  
  37. Boolean EventProc(EventRecord *inEvent);
  38. Boolean EventProc(EventRecord *inEvent)
  39. {
  40.     if (gMyApp == nil) { return false; }
  41.     
  42.     if (inEvent->what == updateEvt)
  43.     {
  44.         gMyApp->DispatchEvent(*inEvent);
  45.     }
  46.  
  47.     return false;
  48. }
  49.  
  50. // ===========================================================================
  51. //        • Main Program
  52. // ===========================================================================
  53.  
  54. void main(void)
  55. {
  56.     ISpGetGlobalElementList(&gElementList);
  57.     
  58.     ISpElementList_Extract(    gElementList,
  59.                             kMaxGlobalElements, 
  60.                             &gNumElements,
  61.                             gElementBuffer);
  62.                             
  63.     gElement = gElementBuffer[gCurElement];
  64.     
  65.     gStatus = ISpElementList_New(0, 0, &gElementList, 0);
  66.             
  67.                                 // Set Debugging options
  68.     SetDebugThrow_(debugAction_Alert);
  69.     SetDebugSignal_(debugAction_Alert);
  70.  
  71.     InitializeHeap(3);                // Initialize Memory Manager
  72.                                     // Parameter is number of Master Pointer
  73.                                     //   blocks to allocate
  74.     
  75.                                     // Initialize standard Toolbox managers
  76.     UQDGlobals::InitializeToolbox(&qd);
  77.     
  78.     new LGrowZone(20000);            // Install a GrowZone function to catch
  79.                                     //    low memory situations.
  80.  
  81.     CPPStarterApp    theApp;            // replace this with your App type
  82.     gMyApp = &theApp;
  83.     theApp.Run();
  84.     
  85. }
  86.  
  87.  
  88. // ---------------------------------------------------------------------------
  89. //        • CPPStarterApp             // replace this with your App type
  90. // ---------------------------------------------------------------------------
  91. //    Constructor
  92.  
  93. CPPStarterApp::CPPStarterApp()
  94. {
  95.     URegistrar::RegisterClass(ISpElementView::class_ID, ISpElementView::CreateISpElementViewStream);
  96.     URegistrar::RegisterClass(ISpEventPane::class_ID, ISpEventPane::CreateISpEventPaneStream);
  97.     URegistrar::RegisterClass(LQuitWindow::class_ID, LQuitWindow::CreateLQuitWindowStream);
  98.  
  99.     // Register functions to create core PowerPlant classes
  100.     
  101.     RegisterAllPPClasses();
  102. }
  103.  
  104.  
  105. // ---------------------------------------------------------------------------
  106. //        • ~CPPStarterApp            // replace this with your App type
  107. // ---------------------------------------------------------------------------
  108. //    Destructor
  109. //
  110.  
  111. CPPStarterApp::~CPPStarterApp()
  112. {
  113.     ISpElement_DisposeVirtual(kNumNeeds, mVirtualElements);
  114. }
  115.  
  116. // ---------------------------------------------------------------------------
  117. //        • StartUp
  118. // ---------------------------------------------------------------------------
  119. //    This function lets you do something when the application starts up. 
  120. //    For example, you could issue your own new command, or respond to a system
  121. //  oDoc (open document) event.
  122.  
  123. void
  124. CPPStarterApp::StartUp()
  125. {
  126.     LWindow *theWindow;
  127.     
  128.     theWindow = LWindow::CreateWindow(1, this);    
  129.     theWindow->Show();
  130.  
  131.     theWindow = LWindow::CreateWindow(2, this);    
  132.     theWindow->Show();
  133.  
  134.  
  135. }
  136.  
  137. // ---------------------------------------------------------------------------
  138. //        • ObeyCommand
  139. // ---------------------------------------------------------------------------
  140. //    Respond to commands
  141.  
  142. Boolean
  143. CPPStarterApp::ObeyCommand(
  144.     CommandT    inCommand,
  145.     void        *ioParam)
  146. {
  147.     Boolean        cmdHandled = true;
  148.  
  149.     switch (inCommand) {
  150.     
  151.         // Deal with command messages (defined in PP_Messages.h).
  152.         // Any that you don't handle will be passed to LApplication
  153.              
  154.         case cmd_New:
  155.                                         // EXAMPLE, create a new window
  156.             break;
  157.  
  158.  
  159.         case cmd_Suspend:
  160.             gStatus = ISpSuspend();
  161.             break;
  162.             
  163.         case cmd_Resume:
  164.             gStatus = ISpResume();
  165.             break;
  166.         
  167.         case cmd_NextElement:
  168.             gStatus = noErr;
  169.             gCurElement = (gCurElement + 1) % gNumElements;
  170.             gElement = gElementBuffer[gCurElement];
  171.             break;
  172.             
  173.         case cmd_PrevElement:
  174.             gStatus = noErr;
  175.             gCurElement = (gCurElement + gNumElements - 1) % gNumElements;
  176.             gElement = gElementBuffer[gCurElement];
  177.             break;
  178.  
  179.         case cmd_AddElement:
  180.             gStatus = ISpElementList_AddElements(    gElementList, 
  181.                                                     gCurElement,
  182.                                                     1,
  183.                                                     &gElement);
  184.             break;
  185.  
  186.         case cmd_DeleteElement:
  187.             gStatus = ISpElementList_RemoveElements(    gElementList, 
  188.                                                         1,
  189.                                                         &gElement);
  190.             break;
  191.  
  192.         case cmd_UIStart:
  193.             gStatus = ISpInit(    kNumNeeds,
  194.                                 mNeeds,
  195.                                 mVirtualElements,
  196.                                 'ISpT',
  197.                                 'foob',
  198.                                 0,
  199.                                 0,
  200.                                 0);
  201.             break;
  202.             
  203.         case cmd_UIConfigure:
  204.             gStatus = ISpConfigure(&EventProc);
  205.             break;
  206.             
  207.         case cmd_UIStop:
  208.             gStatus = ISpStop();
  209.             break;
  210.             
  211.         default:
  212.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  213.             break;
  214.     }
  215.     
  216.     return cmdHandled;
  217. }
  218.  
  219. // ---------------------------------------------------------------------------
  220. //        • FindCommandStatus
  221. // ---------------------------------------------------------------------------
  222. //    This function enables menu commands.
  223. //
  224.  
  225. void
  226. CPPStarterApp::FindCommandStatus(
  227.     CommandT    inCommand,
  228.     Boolean        &outEnabled,
  229.     Boolean        &outUsesMark,
  230.     Char16        &outMark,
  231.     Str255        outName)
  232. {
  233.  
  234.     switch (inCommand) {
  235.     
  236.         // Return menu item status according to command messages.
  237.         // Any that you don't handle will be passed to LApplication
  238.  
  239.         case cmd_New:                    // EXAMPLE
  240.             outEnabled = false;
  241.             break;
  242.             
  243.         case cmd_Suspend:
  244.         case cmd_Resume:
  245.         case cmd_NextElement:
  246.         case cmd_PrevElement:
  247.         case cmd_AddElement:
  248.         case cmd_DeleteElement:
  249.         case cmd_UIStart:
  250.         case cmd_UIConfigure:
  251.         case cmd_UIStop:
  252.             outEnabled = true;            // enable the New command
  253.             break;
  254.  
  255.         default:
  256.             LApplication::FindCommandStatus(inCommand, outEnabled,
  257.                                                 outUsesMark, outMark, outName);
  258.             break;
  259.     }
  260. }
  261.  
  262. void CPPStarterApp::EventResume        (const EventRecord &inMacEvent)
  263. {
  264.     ISpResume();
  265.  
  266.     LApplication::EventResume(inMacEvent);
  267. }
  268.  
  269. void CPPStarterApp::EventSuspend    (const EventRecord &inMacEvent)
  270. {
  271.     ISpSuspend();
  272.     
  273.     LApplication::EventSuspend(inMacEvent);
  274. }
  275.  
  276. void CPPStarterApp::InitNeeds(void)
  277. {
  278.     ISpNeed tempNeeds[kNumNeeds] =
  279.     {
  280.         {
  281.             "\pForward Thrust", 
  282.             kIconSuiteID_YThrust, 
  283.             kISpElementKind_Axis,
  284.             kISpElementLabel_YAxis,
  285.             0
  286.         },
  287.         {
  288.             "\pSide Thrust", 
  289.             kIconSuiteID_XThrust, 
  290.             kISpElementKind_Axis,
  291.             kISpElementLabel_XAxis,
  292.             0
  293.         },
  294.         {
  295.             "\pVertical Thrust", 
  296.             kIconSuiteID_ZThrust, 
  297.             kISpElementKind_Axis,
  298.             kISpElementLabel_ZAxis,
  299.             0
  300.         },
  301.         {
  302.             "\pLook", 
  303.             kIconSuiteID_Look, 
  304.             kISpElementKind_Movement,
  305.             kISpElementLabel_None,
  306.             0
  307.         },
  308.         {
  309.             "\pFire", 
  310.             kIconSuiteID_Fire, 
  311.             kISpElementKind_Button,
  312.             kISpElementLabel_Fire,
  313.             0
  314.         },
  315.         {
  316.             "\pThrust", 
  317.             kIconSuiteID_Thrust, 
  318.             kISpElementKind_Button,
  319.             kISpElementLabel_Fire,
  320.             0
  321.         },
  322.         {
  323.             "\pPause", 
  324.             kIconSuiteID_Pause, 
  325.             kISpElementKind_Button,
  326.             kISpElementLabel_None,
  327.             kISpNeedFlag_NoMultiConfig
  328.         },
  329.         {
  330.             "\pStart/Stop", 
  331.             kIconSuiteID_Start, 
  332.             kISpElementKind_Button,
  333.             kISpElementLabel_Start,
  334.             kISpNeedFlag_NoMultiConfig
  335.         }
  336.     };
  337.     
  338.  
  339.     int itr;
  340.     for(itr = 0; itr < kNumNeeds; itr++)
  341.     {
  342.         mNeeds[itr] = tempNeeds[itr];
  343.     }
  344.  
  345.       ISpElement_NewVirtualFromNeeds(kNumNeeds, mNeeds, mVirtualElements, 0);
  346.  
  347. }